/**
 * @file ice_rtp.h
 * \brief this is rtp part of sipxmpp server.
 *
 * */
#ifndef ICE_RTP_H
#define ICE_RTP_H
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <pthread.h>
#include <openssl/hmac.h>
#include <sys/time.h>
#include "utils.h"
enum ICE_RTP_METHOD
{
	ICE_RTP_METHOD_BINDING_REQUEST = 0x0001,
	ICE_RTP_METHOD_BINDING_RESPONSE = 0x0101,
	ICE_RTP_METHOD_BINDING_ERROR_RESPONSE = 0x0111,
	ICE_RTP_METHOD_SHARED_SECRET_REQUEST = 0x0002,
	ICE_RTP_METHOD_SHARED_SECRET_RESPONSE = 0x0102,
	ICE_RTP_METHOD_SHARED_SECRET_ERROR_RESPONSE = 0x0112
};
enum ICE_RTP_ATTRIBUTE
{
	ICE_RTP_ATTRIBUTE_MAPPED_ADDRESS = 0x0001,
	ICE_RTP_ATTRIBUTE_USERNAME = 0x0006,
	ICE_RTP_ATTRIBUTE_PASSWORD = 0x0007,
	ICE_RTP_ATTRIBUTE_ERROR_CODE = 0x0009
};
struct ice_stun_message_attribute
{
	short len;
	enum ICE_RTP_ATTRIBUTE type;
	char *data;
	struct ice_stun_message_attribute *next;
};
/**
 *
 * */
struct rtp_t
{
	char version;
	char padding;
	char extension;
	char *extension_header;
	char csrc_count;
	
	char marker;
	char payload_type;
	unsigned short sequence;
	unsigned int timestamp;
	unsigned int ssrc;
	char *csrc;
	char *data;
};
struct ice_rtp_connection
{
	int stopping;
	int fd;
	pthread_t reading_thread;
	struct sockaddr_in serv_addr;
	time_t last_negotiation_time;
	char local_username[17];
	char remote_username[17];
	char remote_password[17];
	struct ice_rtp_connection *bridged_rtp;
	char dtmf_to_send_after_ice_success;
	char dtmf_to_send_if_no_data;
	unsigned short rtp_package_sequence;
	unsigned int rtp_package_timespan;
	unsigned int rtp_package_ssrc;
	char payload_type_pcmu;
	char payload_type_telephone_event;
};
int stun_request_ip(int dgram_fd,char *stun_server,int stun_server_port,char *nated_address,int nated_address_len,int *nated_port);
struct ice_rtp_connection *create_new_rtp_connection(int *port);
int ice_rtp_get_local_port(struct ice_rtp_connection *rtp_connection,int *localport);
int glue_rtp_together(struct ice_rtp_connection *rtp1,struct ice_rtp_connection *rtp2);
int resolv_ip(char *server,int port,struct sockaddr_in *address);
int stop_rtp_connection(struct ice_rtp_connection *rtp_connection);
int destroy_rtp_connection(struct ice_rtp_connection *rtp_connection);
#endif
